
#include "Win32Handle.h"

namespace common {

Win32Mutex::Win32Mutex() {
  // Bouml preserved body begin 000367AA
  // Bouml preserved body end 000367AA
}

Win32Mutex::Win32Mutex(const Win32Mutex & source) {
  // Bouml preserved body begin 000368AA
  // Bouml preserved body end 000368AA
}

Win32Mutex::~Win32Mutex() {
  // Bouml preserved body begin 0003682A
  // Bouml preserved body end 0003682A
}

Mutex & Win32Mutex::operator=(const Mutex & source) {
  // Bouml preserved body begin 0003672A
  // Bouml preserved body end 0003672A
}

//Creates new mutex. If initialOwner is true, this thread will gain ownership of this mutex.
Error::code Win32Mutex::Create(bool initialOwner, string name) {
  // Bouml preserved body begin 00033098
  // Bouml preserved body end 00033098
}

//Opens named mutex if such exists.
Error::code Win32Mutex::Open(string name) {
  // Bouml preserved body begin 00033118
  // Bouml preserved body end 00033118
}

//Releases owned mutex.
Error::code Win32Mutex::Release() {
  // Bouml preserved body begin 00033198
  // Bouml preserved body end 00033198
}

//Standard wait for single sync object.
Error::code Win32Mutex::WaitFor(unsigned int timeout) {
  // Bouml preserved body begin 00033218
  // Bouml preserved body end 00033218
}

//Waits for multiple sync objects.
Error::code Win32Mutex::WaitForMultiple(unsigned int count, const SyncObject * handleList, bool waitAll, unsigned int milliseconds) {
  // Bouml preserved body begin 00033298
  // Bouml preserved body end 00033298
}

//Closes Handle to this synchronization object and does some cleanup.
Error::code Win32Mutex::Close() {
  // Bouml preserved body begin 00031F2A
  // Bouml preserved body end 00031F2A
}

Win32Event::Win32Event() {
  // Bouml preserved body begin 0003862A
  // Bouml preserved body end 0003862A
}

Win32Event::Win32Event(const Win32Event & source) {
  // Bouml preserved body begin 0003872A
  // Bouml preserved body end 0003872A
}

Win32Event::~Win32Event() {
  // Bouml preserved body begin 000386AA
  // Bouml preserved body end 000386AA
}

Win32Event & Win32Event::operator=(const Win32Event & source) {
  // Bouml preserved body begin 000387AA
  // Bouml preserved body end 000387AA
}

//Creates new event.
//@param manualReset If true, then this object has to be set to non-signaled manualy trough Reset
//@param initialState If true initial state is signaled.
//@param name Name of the object
Error::code Win32Event::Create(bool manualReset, bool initialState, string name) {
  // Bouml preserved body begin 0002D72A
	Close();

	mNativeHandle = CreateEvent( NULL, manualReset, initialState, name.c_str() );

	if ( mNativeHandle == NULL ) {
		return (Error::code)( ( (int)Error::systemError ) + err );
	}
	return Error::noError;
  // Bouml preserved body end 0002D72A
}

//Opens named mutex if such exists.
Error::code Win32Event::Open(string name) {
  // Bouml preserved body begin 0002D7AA
	Close();

	mNativeHandle = OpenEvent( EVENT_MODIFY_STATE, false, name.c_str() );

	if ( mNativeHandle == NULL ) {
		return (Error::code)( ( (int)Error::systemError ) + err );
	}

	return Error::noError;
  // Bouml preserved body end 0002D7AA
}

//Manualy resets signaled object to non-signaled state.
Error::code Win32Event::Reset() {
  // Bouml preserved body begin 0002D82A
	if ( !ResetEvent( mNativeHandle ) ) {
		return (Error::code)( ( (int)Error::systemError ) + err );
	}

	return Error::noError;
  // Bouml preserved body end 0002D82A
}

//Changes object to signaled state.
Error::code Win32Event::Set() {
  // Bouml preserved body begin 0002D8AA
	if ( !SetEvent( mNativeHandle ) ) {
		return (Error::code)( ( (int)Error::systemError ) + err );
	}

	return Error::noError;
  // Bouml preserved body end 0002D8AA
}

//Standard wait for single sync object.
Error::code Win32Event::WaitFor(unsigned int timeout) {
  // Bouml preserved body begin 0002D92A
	DWORD res = WaitForSingleObject( mNativeHandle, (DWORD)timeout );

	switch ( res ) {
		case WAIT_ABANDONED: {
			return Error::waitAbandoned;
		} break;
		case WAIT_OBJECT_0: {
			return Error::noError;
		} break;
		case WAIT_TIMEOUT: {
			return Error::waitTimeout;
		} break;
		case WAIT_FAILED:
		default: {
			return (Error::code)( ( (int)Error::systemError ) + err );
		}
	}
  // Bouml preserved body end 0002D92A
}

//Waits for multiple sync objects.
Error::code Win32Event::WaitForMultiple(unsigned int count, const SyncObject * handleList, bool waitAll, unsigned int milliseconds) {
  // Bouml preserved body begin 0002D9AA
  // Bouml preserved body end 0002D9AA
}

//Closes Handle to this synchronization object and does some cleanup.
Error::code Win32Event::Close() {
  // Bouml preserved body begin 0003202A
	if ( mNativeHandle != NULL )
	{
		if ( !CloseHandle( mNativeHandle )
		{
			return (Error::code)( ( (int)Error::systemError ) + err );
		}
		mNativeHandle = NULL;
	}

	return Error::noError;
  // Bouml preserved body end 0003202A
}

Win32Semaphore::Win32Semaphore() {
  // Bouml preserved body begin 00036B2A
  // Bouml preserved body end 00036B2A
}

Win32Semaphore::Win32Semaphore(const Win32Semaphore & source) {
  // Bouml preserved body begin 00036C2A
  // Bouml preserved body end 00036C2A
}

Win32Semaphore::~Win32Semaphore() {
  // Bouml preserved body begin 00036BAA
  // Bouml preserved body end 00036BAA
}

Win32Semaphore & Win32Semaphore::operator=(const Win32Semaphore & source) {
  // Bouml preserved body begin 00036CAA
  // Bouml preserved body end 00036CAA
}

Error::code Win32Semaphore::Create(unsigned int initialCount, unsigned int maximumCount, string name) {
  // Bouml preserved body begin 00033318
  // Bouml preserved body end 00033318
}

//Opens existing semaphore.
Error::code Win32Semaphore::Open(string name) {
  // Bouml preserved body begin 00033398
  // Bouml preserved body end 00033398
}

//Increases the count of the specified semaphore object by a specified amount.
Error::code Win32Semaphore::Release(unsigned int releaseCount, unsigned int & previousCount) {
  // Bouml preserved body begin 0002D5AA
  // Bouml preserved body end 0002D5AA
}

//Standard wait for single sync object.
Error::code Win32Semaphore::WaitFor(unsigned int timeout) {
  // Bouml preserved body begin 0002D62A
  // Bouml preserved body end 0002D62A
}

//Waits for multiple sync objects.
Error::code Win32Semaphore::WaitForMultiple(unsigned int count, const SyncObject * handleList, bool waitAll, unsigned int milliseconds) {
  // Bouml preserved body begin 0002D6AA
  // Bouml preserved body end 0002D6AA
}

//Closes Handle to this synchronization object and does some cleanup.
Error::code Win32Semaphore::Close() {
  // Bouml preserved body begin 00031FAA
  // Bouml preserved body end 00031FAA
}


} // namespace common
